package edu.ads.bookloan

class EmployeeResultStrategy implements ResultStrategy{

	@Override
	public Object getResult(def params) {
		def criteria = LoanHistory.createCriteria()
		def loanHistoryList
		Calendar cal = GregorianCalendar.getInstance();
			cal.set(Calendar.HOUR_OF_DAY, 0);
			cal.set(Calendar.MINUTE, 0);
			cal.set(Calendar.SECOND,0);
			cal.set(Calendar.MILLISECOND,0);
			Date currentDate = cal.getTime();
//			Date nextDay = currentDate + 1
			//loanHistoryList = LoanHistory.findAll("from LoanHistory a where a.dateReturned is null and a.expectedReturnDate <= ? order by a.expectedReturnDate desc",[currentDate])
			loanHistoryList = criteria.list(max: params.max, offset: params.offset){
					isNull('dateReturned')
					ge('expectedReturnDate',currentDate)
				!params.sort ? order('dateCreated','asc') : order(params.sort, params.order)
			}
			return loanHistoryList
	}

}
